package masterMind;


import ewe.fx.Color;
import ewe.fx.Image;
import ewe.fx.mImage;
import ewe.graphics.AniImage;
import ewe.graphics.InteractivePanel;
import ewe.ui.Canvas;
import ewe.graphics.*;
public class Jugada extends InteractivePanel{
	final int incy = 40;
	final int incx = 35;
	private int n =5, m =8;
	
	public char[] codigo= {'0', '0', '0', '0', '0'};	
		
	AniImage[] b = new AniImage[n];
	AniImage[] c = new AniImage[m];
	
	void crearColores() {
		Image cols ;
		for(int i=0; i<m;i++) {
			cols =new Image("imgs/"+i+".png");	
			cols.transparent = Color.White;	
			c[i] =  new AniImage(cols);	
			c[i].properties |= AniImage.IsMoveable;			
		}		
	}
		
	public Jugada( )
	{		
		backGround= ewe.fx.Color.White;
		borderWidth = 2; borderStyle = Canvas.EDGE_SUNKEN;
		
		touching = new ImageList();
		for(int i=0;i<n; i++) {
			b[i] =  new AniImage(new mImage("imgs/vacia2.png",Color.White));
			b[i].move(15+(i*44), 20);	
			addImage(b[i]);	
			touching.add(b[i]);
		}
		crearColores();
		
		
		for(int i=0; i<m; i++ ) {
			c[i].move(15+(i*25), 50);	
			addImage(c[i]);	
		}
								
	}
	
	public int cual(AniImage A) {
		for(int i=0; i<m; i++) 
			if(A==c[i])
				return i;	
		return 0;
			
	}
		
	public void droppedOn(ImageDragContext dc)
	{
		int c = cual(dc.image);
		for(int i=0; i<n; i++) {
			if (dc.draggingOver == b[i]){						
				b[i].change(dc.image);
				dc.image.move(15+(25*c), 50);
				codigo[i] = (char)(48+c);
				b[i].refresh();
				break;
			}	
		}						
	}
}



